import random
#创建地址类
class Address:
    def __init__(self,country,province,street,door_number):
        self.country=country
        self.province=province
        self.street=street
        self.door_number=door_number
    def __repr__(self):
        return f"Country:{self.country},Province:{self.province},Street:{self.street},Door_number:{self.door_number}"
#创建用户类
class User:
    def __init__(self,account,name,password,address,balance,bank_name):
        self.account=account
        self.name=name
        self.password=password
        self.address=address
        self.balance=balance
        self.bank_name=bank_name
    def __repr__(self):
        return (f"Account:{self.account},Name:{self.name},Password:{self.password},"
                f"Address:{self.address},Balance:{self.balance},Bank_name:{self.bank_name}")
#创建银行类
class Bank:
    def __init__(self,bank_name):
        self.bank_name=bank_name
        self.user_database={}
    #获得账号
    def gain_account(self):
        return "".join([str(random.randint(0,9)) for _ in range(8)])
    #添加用户
    def add_user(self,name,password,address,balanece):
        if len(self.user_database)>=100:
            return 3
        account=self.gain_account()
        while account in self.user_database:
            return 2
        while account  not in self.user_database:
            account=self.gain_account()
        user=User(account,name,password,address,balance,bank_name)
        self.user_database[account]=user
        return 1
    #存钱
    def deposit(self,account,money):
        if account not in self.user_database:
            return False
        self.user_database[account].balance+=money
        return True
    #存钱
    def withdraw(self,account,password,amount):
        if account not in self.user_database:
            return 1
        if password!=user.password:
            return 2
        if user.balance<amount:
            return 3
        user.balance-=amount
        return 0
     #转账
    def transfer_account(self,from_account,to_account,password,amount):
        if from_account not in self.user_database or to_account not in self.user_database:
            return 1
        user=self.user_database[account]
        if user.password !=password:
            return 2
        if user.balance<amount:
            return 3
        user.balance-=amount
        self.user_database[to_account].balance+=amount
        return 0
    #查询账户
    def query(self,account,password):
        if account not in self.user_database:
            print("该用户不存在")
            return
        if password != user.password:
            print("密码错误")
            return
        print(f"当前帐户:{user.account},密码：{user.password},余额：{user.balance}元,用户居住地址：{user.address},当前账户的开户行")
#界面主函数
def menu(bank):
    while True:
        print("********************")
        print("*    中国工商银行    *")
        print("*    账户管理系统    *")
        print("*       V1.0       *")
        print("********************")
        print("*1.开户             *")
        print("*2.存钱             *")
        print("*3.取钱             *")
        print("*4.转账             *")
        print("*5.查询             *")
        print("*6.Bye！            *")
        print("********************")
        choose=input("请输入选项")
        if choose=="1":
            name=input("请输入姓名：")
            password=input("请输入密码：")
            country=input("请输入国家：")
            province=input("请输入省份：")
            street=input("请输入街道：")
            door_number=input("请输入门牌号：")
            balance=input("请输入存款：")
            address=Address("country, province, street, door_number")
            result=Bank.add_user(name,password,address,balance)
            print("添加结果：",result)
        elif choose=="2":
            account=input("请输入账号：")
            amount=int(input("请输入存款金额："))
            success=Bank.deposit(account,amount)
            if success:
                print("存款成功")
            else:
                print("存款失败")
        elif choose=="3":
            account=input("请输入账户：")
            password=int(input("请输入密码："))
            amount=int(input("请输入存款金额："))
            result=Bank.withdraw(account,password,amount)
            if result==0:
                print("取款成功")
            else:
                print("取款失败，原因：",["账户不对","密码不对","余额不足"][result-1])
        elif choose=="4":
            from_account=input("请输入账户：")
            to_account=input("请输入转账账户")
            password=int(input("请输入密码："))
            amount=int(input("请输入转账金额："))
            result=Bank.transfer_account(from_account,to_account,password,amount)
            if result==0:
                print("转账成功")
            else:
                print("转账失败，原因：",["账户不对","密码不对","余额不足"][result-1])
        elif choose=="5":
            account=input("请输入账户：")
            password=input("请输入密码：")
            Bank.query(account,password)
        elif choose=="6":
            break
        else:
            print("无效输入，请重新选择：")
if __name__ == "__main__":
    bank=Bank("中国工商银行")
    menu(bank)











